'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT, DECIMAL, DATE, BOOLEAN } = app.Sequelize;

  const Enterprise = app.model.define('enterprise', {
    enterpriseId: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'enterprise_id',
      comment: '企业编号'
    },
    enterpriseName: {
      type: STRING(100),
      allowNull: false,
      field: 'enterprise_name',
      comment: '企业名称'
    },
    description: {
      type: TEXT,
      allowNull: true,
      comment: '企业简介'
    },
    imageUrl: {
      type: STRING(500),
      allowNull: true,
      field: 'image_url',
      comment: '企业图片URL'
    },
    benefits: {
      type: TEXT,
      allowNull: true,
      comment: '企业福利信息'
    },
    rating: {
      type: DECIMAL(3, 2),
      allowNull: true,
      defaultValue: 0.00,
      comment: '企业评分'
    },
    status: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'active',
      comment: '企业状态：active-正常，inactive-停用'
    },
    createTime: {
      type: DATE,
      allowNull: false,
      field: 'create_time',
      defaultValue: app.Sequelize.NOW,
      comment: '创建时间'
    },
    updateTime: {
      type: DATE,
      allowNull: false,
      field: 'update_time',
      defaultValue: app.Sequelize.NOW,
      comment: '更新时间'
    }
  }, {
    tableName: 'enterprise',
    timestamps: false,
    comment: '企业信息表'
  });

  // 定义关联关系
  Enterprise.associate = function() {
    // 一个企业有多个岗位
    app.model.Enterprise.hasMany(app.model.Job, {
      foreignKey: 'enterpriseId',
      sourceKey: 'enterpriseId',
      as: 'jobs'
    });
    // 一个企业有多个员工
    app.model.Enterprise.hasMany(app.model.Employee, {
      foreignKey: 'enterpriseId',
      sourceKey: 'enterpriseId',
      as: 'employees'
    });
    // 一个企业有多个评价
    app.model.Enterprise.hasMany(app.model.Review, {
      foreignKey: 'enterpriseId',
      sourceKey: 'enterpriseId',
      as: 'reviews'
    });
  };

  return Enterprise;
};











































